package com.coollang.smartbra.activity;

import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.widget.TextView;

import com.coollang.smartbra.MyAutoLayoutActivity;
import com.coollang.smartbra.R;
import com.coollang.smartbra.utils.WindowManagerUtils;
import com.coollang.smartbra.views.FlowerView;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 雪花飘落页面
 */

public class FinishActivity extends MyAutoLayoutActivity {
    @BindView(R.id.flowerview)
    FlowerView mFlowerView;
    //雪花飘落
    Timer myTimer = null;
    TimerTask mTask = null;

    @BindView(R.id.tv_sport_finish)
    TextView tvSportFinish;
    private Handler mHandler = new Handler() {
        public void dispatchMessage(Message msg) {
            mFlowerView.inva();
        }
    };

    @Override
    protected void initView() {
        setContentView(R.layout.activity_finish);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        int num = getIntent().getIntExtra("num", 0);
        int type = getIntent().getIntExtra("mType", 0);
        if (type != 6) {
            tvSportFinish.setText(num + getString(R.string.unit_ge));
        } else {
            tvSportFinish.setText(num + getString(R.string.unit_s));
        }
        DisplayMetrics dis = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dis);

        float de = dis.density;
        mFlowerView.setWH(WindowManagerUtils.getWindowWidth(this), WindowManagerUtils.getWindowHeight(this), de);
        mFlowerView.loadFlower();
        mFlowerView.addRect();
        mFlowerView.inva();

        myTimer = new Timer();
        mTask = new TimerTask() {
            @Override
            public void run() {
                Message msg = new Message();
                mHandler.sendMessage(msg);
            }
        };
        myTimer.schedule(mTask, 0, 10);

        new CountDownTimer(3500, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                //刷新动画  5s数字倒计时
            }

            @Override
            public void onFinish() {
                finish();
            }
        }.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mFlowerView.recly();
    }

    @Override
    protected void initData() {

    }
}
